#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2022/6/12 15:26
# @Author : Violet
# @File : main.py
# @desc : 主函数
import uvicorn
from fastapi import FastAPI
from core import logger
from register import register_exception, register_router, register_middleware, register_cors

# ---------------------------------------------美观线-------------------------------------------------------

app = FastAPI()


def create_app():
    """ 注册中心 """

    register_exception(app)  # 注册捕获全局异常

    register_router(app)  # 注册路由

    register_middleware(app)  # 注册请求响应拦截

    register_cors(app)  # 注册跨域请求

    logger.info("日志初始化成功！！！")  # 初始化日志


@app.on_event("startup")
async def startup():
    create_app()  # 加载注册中心


@app.on_event("shutdown")
async def shutdown():
    pass


if __name__ == '__main__':
    uvicorn.run(app='main:app', host="localhost", port=38000, log_level="info")
